﻿package com.urbansquall.ginger
{
	
import com.urbansquall.ginger.AnimationController;
import flash.utils.Dictionary;
	
public class AnimationFactory
{
	private var m_animations : Dictionary;
	
	public function AnimationFactory()
	{
		m_animations = new Dictionary();
	}
	
	public function register( a_name : String, a_animationController : AnimationController ) : void
	{
		if( m_animations[ a_name ] != null )
		{
			throw new Error( "AnimationFactory:register. There is already an animation with the name [" + a_name + "]" );
		}
		
		m_animations[ a_name ] = a_animationController;
	}
	
	public function instantiate( a_name : String ) : AnimationController
	{
		if( m_animations[ a_name ] == null )
		{
			throw new Error( "AnimationFactory:instantiate. There is no animation with the name [" + a_name + "]" );
		}
		
		var animationController : AnimationController = m_animations[ a_name ];
		return animationController.copy();
	}
	
	public function dispose() : void
	{
		for each( var key : String in m_animations )
		{
			delete m_animations[ key ];
			m_animations[ key ] = null;
		}
		
		m_animations = null;
	}
	
}
}